package com.wzapp.sitposture.eshop.service.impl;

import com.wzapp.sitposture.common.error.CustomizedException;
import com.wzapp.sitposture.common.util.IdWorker;
import com.wzapp.sitposture.eshop.service.IdGeneratorService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;

/**
 * Created by qianglong on 2018/2/6.
 */
@Service
public class IdGeneratorServiceImpl implements IdGeneratorService {

    private static final Logger log = LoggerFactory.getLogger(IdGeneratorServiceImpl.class); 
    
    @Override
    public String generatorOrderCode() throws CustomizedException {

        IdWorker idWorker = IdWorker.getFlowIdWorkerInstance();
        try {
            return String.valueOf(idWorker.nextId());
        }catch (Exception e){
            log.error("IdGeneratorServiceImpl generatorOrderCode error,{}",e);
            throw new CustomizedException("eShop.order.get.orderCode.error");
        }
    }
}
